
#ifndef _UTIL_CLIENT_H_
#define _UTIL_CLIENT_H_
#include "xtypes.h"
#include "util_thread.h"
#include "util_sync.h"
#include "util_stream.h"
#include "util_socket.h"




/*---------------------------------------------------------------------------
Types
---------------------------------------------------------------------------*/
typedef struct{
	CxThread * pThread;	
	CConnSocket ** ppConnSocket;
	CxStream ** ppStream;
	bool_t bQueryQuit;
}t_ClientRecvThreadArgList;

typedef struct{
	CxThread * pThread;	
	CConnSocket ** ppConnSocket;
	CxStream ** ppStream;
	CxSyncEvent ** ppSendEvent;
	bool_t bQueryQuit;
}t_ClientSendThreadArgList;




/*---------------------------------------------------------------------------
Classes
---------------------------------------------------------------------------*/
class CClientConnection
{
public:	
	xResult PostConnection( SocketAddr_t sa );
	xResult Disconnect();
	bool_t IsConnected();
	void Hearbeat();
	xResult SendDataPacket( wildptr_t _Data, int_t _Size );

public:
	static CClientConnection * Create();
	virtual void Release();

public:
	CClientConnection();
	virtual ~CClientConnection();

protected:
	virtual void OnConnect();
	virtual void OnDisconnect();
	virtual void OnHeartbeat();
	virtual void OnDataPacket( wildptr_t _Data, int_t _Size );
	virtual void OnConnectFailed();

protected:
	void _Init();
	void _Alloc();
	void _Tidy();

protected:
	CConnSocket * m_pConnSocket;
	CxThread * m_pRecvThread;
	CxThread * m_pSendThread;
	CxSyncEvent * m_pSendSyncEvent;

	CxStream * m_pRecvStream;
	CxStream * m_pSendStream;

	t_ClientRecvThreadArgList m_RecvThreadArgList;
	t_ClientSendThreadArgList m_SendThreadArgList;

};







#endif //_UTIL_CLIENT_H_



